package app.netant.bt.btcat;

import org.jsoup.select.Elements;

import app.netant.NetAntBase;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.enviroment.Enviroment;
import cn.lily.com.lang.number.MathUtil;
/**
 * 页面分析
 * @author JiaJ
 * @date 2018年6月28日
 *
 */
public class BtCatNetPage extends NetAntBase {

	public BtCatNetPage(String netSite) {
		super(netSite);
	}
	
	public void analyse(){
		
		Elements activePart = document.select("#wrapper #content #wall .search-item.detail-width");
		for(int i=0;i<activePart.size();i++){
			
			String href = "https://btcat.org" + activePart.get(i).select(".item-title a").attr("href");
			
			System.out.println(href+"开始处理");
				
			try {
				
				Enviroment.getEnv().getLogBean().beginLog();

				DataTable dataTable = DBFactory.getThreadDB().executeQueryTable("select * from ${schema}.LEO_BTCAT_RES_INFO where RES_URL='"+href+"'");
				if(dataTable.next()){
					continue;
				}
				
				BtCatEntity entity = new BtCatEntity();
				entity.setResUrl(href);
				
				BtCatNetDetail detail = new BtCatNetDetail(href);
				detail.setEntity(entity);
				detail.analyse();
				
				entity.insert();
				
				Enviroment.getEnv().getLogBean().endLog();
				
			} catch (Exception e) {
				e.printStackTrace();				
				DBFactory.getThreadDB().executeUpdate("insert into ${schema}.LEO_BTCAT_RES_EXCEP (EXCEP_ID,EXCEP_URL,EXCEP_LEVEL) "
						+ "values ('"+System.currentTimeMillis()+MathUtil.random(3)+"','"+href+"','2')");

				continue;
			}

		}
		
		
	}

}
